<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
	<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${pageContext.request.contextPath }/css/css.css" rel="stylesheet">
<script type="text/javascript" src="${pageContext.request.contextPath }/jquery/jquery-1.8.2.js"></script>
<title>Insert title here</title>
</head>
<body>
	<form action="list" method="post">
		发薪单名称 <input type="text" name="rname" value="${roll.rname }">
		&emsp;&emsp; 
		公司 
		<select name="comid" onchange="change1()" >
			<option value="">请选择</option>
		</select> &emsp; 
		事业部
		 <select name="busid" onchange="change2()">
			<option value="">请选择</option>
		</select> &emsp; 
		部门 
		<select name="deptid">
			<option value="">请选择</option>
		</select> &emsp;&emsp;&emsp;&emsp; 
		<input type="submit" value="查询">
		<table>
			<tr>
				<td>
				<input type="checkbox" onclick="quanxuan(this)">
				<input type="button" value="批量删除" onclick="pisan()"></td>
				<td>发薪单编号</td>
				<td>发薪单名称</td>
				<td>公司</td>
				<td>事业部</td>
				<td>部门</td>
				<td>发放总金额</td>
				<td>发薪人员</td>
				<td>创建时间</td>
				<td>文件/图片</td>
				<td>文件下载</td>
				<td>操作 
				<a href="toAdd"><input type="button" value="添加"></a>
				</td>
			</tr>
			<c:forEach items="${pg.list }" var="l">
				<tr>
					<td><input type="checkbox" value="${l.id }"  class="c1" >
					</td>
					<td>${l.code }</td>
					<td>${l.rname }</td>
					<td>${l.comName }</td>
					<td>${l.busName }</td>
					<td>${l.deptName }</td>
					<td>${l.account }</td>
					<td>
					<c:forEach items="${l.paymasters }" var="p">
						${p.name }
					</c:forEach>
					</td>
					<td><fmt:formatDate value="${l.cretime }"
							pattern="yyyy-MM-dd HH:mm:ss" /></td>
					<td>
					<img src="${l.bills }" height="30px" width="30px">
					</td>
					<td><a>下载</a></td>
					<td><input type="button" value="删除" onclick="shanchu(${l.id})">
						<a href="toUp?id=${l.id }"><input type="button" value="修改"></a>
					</td>
				</tr>
			</c:forEach>
			<jsp:include page="/jquery/page.jsp"></jsp:include>
		</table>
	</form>
	
<script type="text/javascript">
		$.post(
			"sanji",
			{id:0},
			function(msg){
				for (var i = 0; i < msg.length; i++) {
					$("[name='comid']").append("<option value='"+msg[i].id+"'>"+msg[i].name+"</option>")
				}
				$("[name='comid']").val('${roll.comid}')
				$("[name='comid']").trigger("change")
			},
			"json"
		)

		function change1(){
			var id=$("[name='comid']").val();
			$.post(
					"sanji",
					{id:id},
					function(msg){
						for (var i = 0; i < msg.length; i++) {
							$("[name='busid']").append("<option value='"+msg[i].id+"'>"+msg[i].name+"</option>")
						}
						$("[name='busid']").val('${roll.busid}')
						$("[name='busid']").trigger("change")
					},
					"json"
				)
		}
		function change2(){
			var id=$("[name='busid']").val();
			$.post(
					"sanji",
					{id:id},
					function(msg){
						for (var i = 0; i < msg.length; i++) {
							$("[name='deptid']").append("<option value='"+msg[i].id+"'>"+msg[i].name+"</option>")
						}
						$("[name='deptid']").val('${roll.deptid}')
					},
					"json"
				)
		}

function sanchu(id){
	if(confirm("确认删除吗？")){
		$.post(
				"deleteRoll",
				{id:id},
				function(msg){
					if(msg>0){
						alert("删除成功");
						location=location;
					}
				},
				"json"
		)
	}
}

function quanxuan(thiz){
	$(".c1").attr("checked",thiz.checked);
}

function pisan(){
	
	var id=$(".c1:checked").map(function(){
		return $(this).val();
	}).get().join()
	sanchu(id)
	
}


</script>

</body>
</html>